package com.ymatou.iapi.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.LoginPasswordRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.enums.LoginNameEnum;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.CreateUserCall;
import com.ymatou.iapi.userservice.service.LoginPasswordRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.JUserCallService;

/**
 * 验证登录密码Test FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_LoginPasswordRequestDto {
	private static LoginPasswordRequestDtoBean loginpasswordrequestdtoBean;
	private static LoginPasswordRequestDtoCall loginpasswordrequestdtoCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("验证登录密码Test");
	}

	@Before
	public void caseUp() {
		loginpasswordrequestdtoBean = new LoginPasswordRequestDtoBean();
		loginpasswordrequestdtoCall = new LoginPasswordRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(loginpasswordrequestdtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LoginPasswordRequestDto_001() {
		Logger.start(true, "验证登录密码,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			
			loginpasswordrequestdtoBean.setLoginId(cur.getLoginId());
			loginpasswordrequestdtoBean.setLoginIdType(LoginNameEnum.LoginId);
			loginpasswordrequestdtoBean.setAppSource("App");
			loginpasswordrequestdtoBean.setPassword(cur.getLoginPassword());
			loginpasswordrequestdtoCall.setData(loginpasswordrequestdtoBean);
			loginpasswordrequestdtoCall.callService();
			
			Logger.verifyEquals("true", loginpasswordrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals(uid, loginpasswordrequestdtoCall.getJsonObject().get("Result").getAsJsonObject().get("userId").getAsInt(), "验证userId");
			Logger.verifyEquals("200", loginpasswordrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LoginPasswordRequestDto_002() {
		Logger.start(true, "登录密码错误,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			
			loginpasswordrequestdtoBean.setLoginId(cur.getLoginId());
			loginpasswordrequestdtoBean.setLoginIdType(LoginNameEnum.LoginId);
			loginpasswordrequestdtoBean.setAppSource("App");
			loginpasswordrequestdtoBean.setPassword(cur.getLoginPassword()+1);
			loginpasswordrequestdtoCall.setData(loginpasswordrequestdtoBean);
			loginpasswordrequestdtoCall.callService();
			
			Logger.verifyEquals("false", loginpasswordrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100003", loginpasswordrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("用户登录密码错误", loginpasswordrequestdtoCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LoginPasswordRequestDto_003() {
		Logger.start(true, "loginid为空验证登录密码,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			
			loginpasswordrequestdtoBean.setLoginId(null);
			loginpasswordrequestdtoBean.setLoginIdType(LoginNameEnum.LoginId);
			loginpasswordrequestdtoBean.setAppSource("App");
			loginpasswordrequestdtoBean.setPassword(cur.getLoginPassword()+1);
			loginpasswordrequestdtoCall.setData(loginpasswordrequestdtoBean);
			loginpasswordrequestdtoCall.callService();
			
			Logger.verifyEquals("false", loginpasswordrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", loginpasswordrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("loginId:loginId can't empty", loginpasswordrequestdtoCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LoginPasswordRequestDto_004() {
		Logger.start(true, "不输入密码,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			
			loginpasswordrequestdtoBean.setLoginId(null);
			loginpasswordrequestdtoBean.setLoginIdType(LoginNameEnum.LoginId);
			loginpasswordrequestdtoBean.setAppSource("App");
		//	loginpasswordrequestdtoBean.setPassword(cur.getLoginPassword()+1);
			loginpasswordrequestdtoCall.setData(loginpasswordrequestdtoBean);
			loginpasswordrequestdtoCall.callService();
			
			Logger.verifyEquals("false", loginpasswordrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", loginpasswordrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("password:password can't empty", loginpasswordrequestdtoCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}